﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SpeechLib;
using System.IO;

namespace TextToSpeech
{
    /// <summary>
    /// Implementation of TTS using Speech API (SAPI 5.1)
    /// </summary>
    public class SapiTTS : TTS
    {
        // Constructor asociated to the Speech API
        SpVoice voice;
        //List of voices
        List<String> voices;
        
        /// <summary>
        /// Default constructor. Create an instance of a SpVoice object
        /// and set the voice to be used. The default voice is the girl one.
        /// </summary>
        public SapiTTS()
        {
            voice = new SpVoice();
            voice.Voice = voice.GetVoices(String.Empty, String.Empty).Item(2);
        }
        /// <summary>
        /// Method used to speak a given message
        /// </summary>
        /// <param name="tts">Message to be "spoken" by the computer</param>
        public override void speak(string tts)
        {
            voice.Speak(tts);
            voice.WaitUntilDone(-1);
        }

        public void speakToStream(string path, string tts)
        {            
            SpFileStream fileStream = new SpFileStream();
            fileStream.Open(path, SpeechStreamFileMode.SSFMCreateForWrite);
            voice.AudioOutputStream = fileStream;
            voice.Speak(tts);
            fileStream.Close();
        }

    }
}
